package com.dong.dao;

import com.dong.entity.Employee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 多对一，在mybatis称为：一对一
 */
public interface IEmployeeDao {
    @Select("select * from employee")
//    封装employee属性，配置dept映射
    @Results(id="eMap",value = {
            @Result(id=true,column = "e_id",property = "e_id"),
            @Result(column = "d_id",property = "d_id"),
            @Result(column = "e_name",property = "e_name"),
            @Result(column = "e_salary",property = "e_salary"),
            @Result(column = "d_id",property = "dept",one=@One(select = "com.dong.dao.IDeptDao.findById",fetchType = FetchType.EAGER))
    })
    List<Employee> findAllEmpAndDept();

    /**
     * 使用一查询多，需要添加通过外键查询
     * @param id
     * @return
     */
    @Select("select * from employee where d_id=#{id}")
    List<Employee> findByDeptId(int id);
}
